package week0401;

import java.util.Arrays;

public class Main7 {
	public static void main(String[] args) {
		Person[] persons=new Person[3];
			persons[0]=new Person("zheng", 15);
			persons[1]=new Person("zhang", 25);
			persons[2]=new Person("zheng", 18);
			Arrays.sort(persons);
			System.out.println(Arrays.toString(persons));

	}

}

class Person implements Comparable<Person>{
	String name;
	int age;
	public Person(String name, int age) {
		this.name = name;
		this.age = age;
	}
	public String getName() {
		return name;
	}
	public int getAge() {
		return age;
	}

	public int compareTo(Person o) {
		if(name.compareTo(o.getName())!=0)
			return name.compareTo(o.getName());
		if(this.getAge()>o.getAge())
			return -1;
		if(this.getAge()<o.getAge())
			return 1;
		return 0;
	}
	@Override
	public String toString() {
		return "Person [name=" + name + ", age=" + age + "]";
	}

}